# Crear el gráfico de barras con letras estadísticasggplot(grupos, aes(x = geno, y = lfa, fill = riego)) +# Asegúrate de que "lfa" sea el nombre correctogeom_bar(stat ="identity", position =position_dodge(), color ="black") +labs(title ="Comparación de Medias - Prueba de Tukey", x ="Genotipos", y ="FTL") +theme_minimal() +theme(legend.title =element_blank()) +scale_fill_discrete(name ="Riego") +geom_text(aes(label = groups, y = lfa +0.05), # Usar 'groups' en lugar de 'M'position =position_dodge(0.9), vjust =0) # Ajustar el espaciado de las letras
7 emmeans: Comparación de medias
Código
model <- lme4::lmer(formula = hi ~ riego + geno + riego * geno + (1| bloque), data = fb)anova(model)## Analysis of Variance Table## npar Sum Sq Mean Sq F value## riego 1 0.12176 0.121758 37.8165## geno 14 2.70077 0.192912 59.9161## riego:geno 14 0.07762 0.005544 1.7219library(emmeans)library(multicmp)library(multcompView)cm1 <-emmeans(model, ~ geno | riego) %>%cld(Letters=letters, reversed = T)cm1## riego = irrigado:## geno emmean SE df lower.CL upper.CL .group ## G07 0.749 0.0278 65.8 0.6938 0.805 a ## G15 0.680 0.0278 65.8 0.6248 0.736 ab ## G11 0.645 0.0278 65.8 0.5898 0.701 abc ## G03 0.625 0.0278 65.8 0.5695 0.681 abc ## G09 0.605 0.0278 65.8 0.5490 0.660 bcd ## G05 0.580 0.0278 65.8 0.5249 0.636 bcde ## G10 0.555 0.0278 65.8 0.4993 0.610 cdef ## G04 0.546 0.0278 65.8 0.4903 0.601 cdefg ## G12 0.498 0.0278 65.8 0.4427 0.554 defg ## G01 0.472 0.0278 65.8 0.4168 0.528 efgh ## G02 0.455 0.0278 65.8 0.3995 0.511 fgh ## G14 0.436 0.0278 65.8 0.3807 0.492 fgh ## G08 0.429 0.0278 65.8 0.3735 0.485 gh ## G13 0.350 0.0278 65.8 0.2946 0.406 h ## G06 0.221 0.0278 65.8 0.1653 0.276 i## ## riego = sequia:## geno emmean SE df lower.CL upper.CL .group ## G07 0.689 0.0278 65.8 0.6335 0.745 a ## G11 0.665 0.0278 65.8 0.6097 0.721 a ## G03 0.593 0.0278 65.8 0.5371 0.648 ab ## G15 0.590 0.0278 65.8 0.5340 0.645 ab ## G10 0.582 0.0278 65.8 0.5261 0.637 ab ## G09 0.511 0.0278 65.8 0.4556 0.567 bc ## G04 0.486 0.0278 65.8 0.4302 0.541 bc ## G05 0.446 0.0278 65.8 0.3908 0.502 cd ## G01 0.441 0.0278 65.8 0.3852 0.496 cd ## G02 0.402 0.0278 65.8 0.3467 0.458 cde ## G12 0.402 0.0278 65.8 0.3467 0.458 cde ## G14 0.389 0.0278 65.8 0.3335 0.445 cde ## G13 0.346 0.0278 65.8 0.2904 0.402 de ## G08 0.315 0.0278 65.8 0.2598 0.371 e ## G06 0.136 0.0278 65.8 0.0807 0.192 f ## ## Degrees-of-freedom method: kenward-roger ## Confidence level used: 0.95 ## P value adjustment: tukey method for comparing a family of 15 estimates ## significance level used: alpha = 0.05 ## NOTE: If two or more means share the same grouping symbol,## then we cannot show them to be different.## But we also did not show them to be the same.cm2 <-emmeans(model, ~ riego | geno) %>%cld(Letters=letters, reversed = T)cm2## geno = G01:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.472 0.0278 65.8 0.4168 0.528 a ## sequia 0.441 0.0278 65.8 0.3852 0.496 a ## ## geno = G02:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.455 0.0278 65.8 0.3995 0.511 a ## sequia 0.402 0.0278 65.8 0.3467 0.458 a ## ## geno = G03:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.625 0.0278 65.8 0.5695 0.681 a ## sequia 0.593 0.0278 65.8 0.5371 0.648 a ## ## geno = G04:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.546 0.0278 65.8 0.4903 0.601 a ## sequia 0.486 0.0278 65.8 0.4302 0.541 a ## ## geno = G05:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.580 0.0278 65.8 0.5249 0.636 a ## sequia 0.446 0.0278 65.8 0.3908 0.502 b ## ## geno = G06:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.221 0.0278 65.8 0.1653 0.276 a ## sequia 0.136 0.0278 65.8 0.0807 0.192 b ## ## geno = G07:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.749 0.0278 65.8 0.6938 0.805 a ## sequia 0.689 0.0278 65.8 0.6335 0.745 a ## ## geno = G08:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.429 0.0278 65.8 0.3735 0.485 a ## sequia 0.315 0.0278 65.8 0.2598 0.371 b ## ## geno = G09:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.605 0.0278 65.8 0.5490 0.660 a ## sequia 0.511 0.0278 65.8 0.4556 0.567 b ## ## geno = G10:## riego emmean SE df lower.CL upper.CL .group## sequia 0.582 0.0278 65.8 0.5261 0.637 a ## irrigado 0.555 0.0278 65.8 0.4993 0.610 a ## ## geno = G11:## riego emmean SE df lower.CL upper.CL .group## sequia 0.665 0.0278 65.8 0.6097 0.721 a ## irrigado 0.645 0.0278 65.8 0.5898 0.701 a ## ## geno = G12:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.498 0.0278 65.8 0.4427 0.554 a ## sequia 0.402 0.0278 65.8 0.3467 0.458 b ## ## geno = G13:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.350 0.0278 65.8 0.2946 0.406 a ## sequia 0.346 0.0278 65.8 0.2904 0.402 a ## ## geno = G14:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.436 0.0278 65.8 0.3807 0.492 a ## sequia 0.389 0.0278 65.8 0.3335 0.445 a ## ## geno = G15:## riego emmean SE df lower.CL upper.CL .group## irrigado 0.680 0.0278 65.8 0.6248 0.736 a ## sequia 0.590 0.0278 65.8 0.5340 0.645 b ## ## Degrees-of-freedom method: kenward-roger ## Confidence level used: 0.95 ## significance level used: alpha = 0.05 ## NOTE: If two or more means share the same grouping symbol,## then we cannot show them to be different.## But we also did not show them to be the same.cm3 <-emmeans(model, ~ riego * geno) %>%cld(Letters=letters, reversed = T)cm3## riego geno emmean SE df lower.CL upper.CL .group ## irrigado G07 0.749 0.0278 65.8 0.6938 0.805 a ## sequia G07 0.689 0.0278 65.8 0.6335 0.745 ab ## irrigado G15 0.680 0.0278 65.8 0.6248 0.736 abc ## sequia G11 0.665 0.0278 65.8 0.6097 0.721 abc ## irrigado G11 0.645 0.0278 65.8 0.5898 0.701 abcd ## irrigado G03 0.625 0.0278 65.8 0.5695 0.681 abcde ## irrigado G09 0.605 0.0278 65.8 0.5490 0.660 bcdef ## sequia G03 0.593 0.0278 65.8 0.5371 0.648 bcdefg ## sequia G15 0.590 0.0278 65.8 0.5340 0.645 bcdefg ## sequia G10 0.582 0.0278 65.8 0.5261 0.637 bcdefgh ## irrigado G05 0.580 0.0278 65.8 0.5249 0.636 bcdefgh ## irrigado G10 0.555 0.0278 65.8 0.4993 0.610 bcdefghi ## irrigado G04 0.546 0.0278 65.8 0.4903 0.601 cdefghi ## sequia G09 0.511 0.0278 65.8 0.4556 0.567 defghij ## irrigado G12 0.498 0.0278 65.8 0.4427 0.554 efghij ## sequia G04 0.486 0.0278 65.8 0.4302 0.541 fghijk ## irrigado G01 0.472 0.0278 65.8 0.4168 0.528 fghijkl ## irrigado G02 0.455 0.0278 65.8 0.3995 0.511 ghijkl ## sequia G05 0.446 0.0278 65.8 0.3908 0.502 hijklm ## sequia G01 0.441 0.0278 65.8 0.3852 0.496 ijklm ## irrigado G14 0.436 0.0278 65.8 0.3807 0.492 ijklm ## irrigado G08 0.429 0.0278 65.8 0.3735 0.485 ijklm ## sequia G02 0.402 0.0278 65.8 0.3467 0.458 jklm ## sequia G12 0.402 0.0278 65.8 0.3467 0.458 jklm ## sequia G14 0.389 0.0278 65.8 0.3335 0.445 jklm ## irrigado G13 0.350 0.0278 65.8 0.2946 0.406 klmn ## sequia G13 0.346 0.0278 65.8 0.2904 0.402 lmn ## sequia G08 0.315 0.0278 65.8 0.2598 0.371 mn ## irrigado G06 0.221 0.0278 65.8 0.1653 0.276 no## sequia G06 0.136 0.0278 65.8 0.0807 0.192 o## ## Degrees-of-freedom method: kenward-roger ## Confidence level used: 0.95 ## P value adjustment: tukey method for comparing a family of 30 estimates ## significance level used: alpha = 0.05 ## NOTE: If two or more means share the same grouping symbol,## then we cannot show them to be different.## But we also did not show them to be the same.
7.1 Gráfico
Código
# Convertir las medias estimadas a un dataframecm1_df <-as.data.frame(cm1)# Ver el contenido del dataframe para asegurarnos de que tiene las columnas correctasprint(cm1_df)## riego = irrigado:## geno emmean SE df lower.CL upper.CL .group ## G07 0.7493642 0.02782682 65.85 0.6938038 0.8049247 a ## G15 0.6804093 0.02782682 65.85 0.6248488 0.7359697 ab ## G11 0.6454090 0.02782682 65.85 0.5898486 0.7009694 abc ## G03 0.6250623 0.02782682 65.85 0.5695019 0.6806228 abc ## G09 0.6045334 0.02782682 65.85 0.5489730 0.6600939 bcd ## G05 0.5804779 0.02782682 65.85 0.5249175 0.6360383 bcde ## G10 0.5548184 0.02782682 65.85 0.4992580 0.6103788 cdef ## G04 0.5458959 0.02782682 65.85 0.4903355 0.6014563 cdefg ## G12 0.4982785 0.02782682 65.85 0.4427181 0.5538389 defg ## G01 0.4723838 0.02782682 65.85 0.4168234 0.5279442 efgh ## G02 0.4550825 0.02782682 65.85 0.3995221 0.5106429 fgh ## G14 0.4362839 0.02782682 65.85 0.3807235 0.4918443 fgh ## G08 0.4290359 0.02782682 65.85 0.3734754 0.4845963 gh ## G13 0.3501105 0.02782682 65.85 0.2945501 0.4056709 h ## G06 0.2208924 0.02782682 65.85 0.1653319 0.2764528 i## ## riego = sequia:## geno emmean SE df lower.CL upper.CL .group ## G07 0.6890640 0.02782682 65.85 0.6335036 0.7446244 a ## G11 0.6652481 0.02782682 65.85 0.6096877 0.7208085 a ## G03 0.5926673 0.02782682 65.85 0.5371069 0.6482277 ab ## G15 0.5895516 0.02782682 65.85 0.5339911 0.6451120 ab ## G10 0.5817049 0.02782682 65.85 0.5261445 0.6372653 ab ## G09 0.5111352 0.02782682 65.85 0.4555748 0.5666956 bc ## G04 0.4857444 0.02782682 65.85 0.4301839 0.5413048 bc ## G05 0.4463163 0.02782682 65.85 0.3907559 0.5018767 cd ## G01 0.4407712 0.02782682 65.85 0.3852108 0.4963316 cd ## G02 0.4022553 0.02782682 65.85 0.3466949 0.4578157 cde ## G12 0.4022395 0.02782682 65.85 0.3466791 0.4577999 cde ## G14 0.3890153 0.02782682 65.85 0.3334549 0.4445757 cde ## G13 0.3459851 0.02782682 65.85 0.2904247 0.4015455 de ## G08 0.3153312 0.02782682 65.85 0.2597708 0.3708916 e ## G06 0.1362879 0.02782682 65.85 0.0807275 0.1918483 f ## ## Degrees-of-freedom method: kenward-roger ## Confidence level used: 0.95 ## P value adjustment: tukey method for comparing a family of 15 estimates ## significance level used: alpha = 0.05 ## NOTE: If two or more means share the same grouping symbol,## then we cannot show them to be different.## But we also did not show them to be the same.# Crear el gráfico de barras con los resultados de las medias estimadas de emmeansggplot(cm1_df, aes(x = geno, y = emmean, fill = riego)) +# Cambia "emmean" por la columna de las medias estimadasgeom_bar(stat ="identity", position =position_dodge(), color ="black") +labs(title ="Comparación de Medias - Medias Estimadas", x ="Genotipos", y ="hi") +theme_minimal() +theme(legend.title =element_blank()) +scale_fill_discrete(name ="Riego")
Código
dtcm <-as.data.frame(cm2) %>%rename(sig =".group")ggplot(dtcm, aes(x = geno, y = emmean, fill = riego)) +geom_bar(stat ="identity", position ="dodge", color ="black") +geom_text(aes(label = sig, y = emmean*1*1),position =position_dodge(width =0.9),vjust =0) +labs(x ="Genotipo", y ="HI", fill ="Riego") +theme_minimal() +theme(axis.text.x =element_text(angle =45, hjust =1)) +ggtitle("Gráfico de barras: LFA por genotipo y riego")
p1 <- fb %>%ggplot(data = ., aes(x = geno, y = hi, fill = riego)) +geom_boxplot() +labs(x="Genotipos" , y ="Indice de cosecha" , fill ="Tratamiento" , title ="Eficiencia de riego" , subtitle ="Índice de cosecha" ,caption ="n = 150") +theme_classic() +theme(plot.title =element_text(hjust =0.5))p1
9.2 Sqater plot
Código
p2 <- fb %>%ggplot(data = ., aes(x = wue, y = hi, colour = riego)) +geom_point() +labs(x="Eficiencia del uso del agua" , y ="Indice de cosecha" , fill ="Tratamiento" , title ="Eficiencia del uso del agua en papa" , subtitle ="Eficiencia del uso del agua en tubérculo " ,caption ="n = 150") +theme_bw()p2